<?php 

/**
 * Joomla! 1.5 component arts_curriculum
 * @package    arts_curriculum
 * @subpackage 
 * @author     Chris Borkowski {@link http://www.guggenheim.org}
 * @author     Created on 31-August-2009
 */

	// no direct access
	defined( '_JEXEC' ) or die( 'Restricted access' );
	
	
	// Include library dependencies
	  jimport('joomla.filter.input');
	/**
	  * Arts_curriculum Item Table class
	  * @package Arts_curriculum
	  */
	  class TableItem extends JTable {
	  /**
	  * Primary Key
	  *
	  * @var int
	  */
	  var $id = null;
	 /**
	  * @var int
	  */
	  var $catid = null;
	 /**
	  * @var string
	  */
	  var $title = null;
	  
	  /**
	  * @var string
	  */
	  var $alias = null;
	 /**
	  * @var string
	  */
	  var $lesson_number = null;
	   /**
	  * @var string
	  */
	  var $lesson_name = null;
	   /**
	  * @var string
	  */
	  var $exhibit_name = null;
	   /**
	  * @var string
	  */
	  var $artist_name = null;
	   /**
	  * @var string
	  */
	  var $subject = null;
	   /**
	  * @var string
	  */
	  var $medium = null;
	   /**
	  * @var string
	  */
	  var $article_title = null;
	   /**
	  * @var string
	  */
	  var $main_body = null;
	   /**
	  * @var string
	  */
	  var $view_n_dis = null;
	   /**
	  * @var string
	  */
	  var $further_reading = null;
	   /**
	  * @var string
	  */
	  
	  var $additional_resources = null;
	   /**
	  * @var string
	  */
	  
	  var $vocabulary = null;
	   /**
	  * @var string
	  */
	  
	  var $notes = null;
	   /**
	  * @var string
	  */
	  var $image1 = null;
	  var $imgcap1 = null;
	   /**
	  * @var string
	  */
	  var $image2 = null;
	  var $imgcap2 = null;
	  /**
	  * @var string
	  */
	  var $image3 = null;
	  var $imgcap3 = null;
	  /**
	  * @var string
	  */
	  var $image4 = null;
	  var $imgcap4 = null;
	  /**
	  * @var string
	  */
	  var $asset1 = null;
	   /**
	  * @var string
	  */
	  var $asset2 = null;
	   /**
	  * @var string
	  */
	  var $asset3 = null;
	   /**
	  * @var string
	  */
	  var $asset4 = null;
	   /**
	  * @var string
	  */
	  var $video1 = null;
	   /**
	  * @var string
	  */
	  var $video2 = null;
	   /**
	  * @var string
	  */
	  var $audio1 = null;
	   /**
	  * @var string
	  */
	  var $audio2 = null;
	  
	 /**
	  * @var datetime
	  */
	  var $created = null;
	 /**
	  * @var int
	  */
	  var $created_by = null;
	 /**
	  * @var string
	  */
	  var $created_by_alias = null;
	 /**
	  * @var datetime
	  */
	  var $modified = null;
	
	 /**
	  * @var int
	  */
	  var $modified_by = null;
	 /**
	  * @var boolean
	  */
	  var $checked_out = 0;
	 /**
	  * @var time
	  */
	  var $checked_out_time = 0;
	 /**
	  * @var int
	  */
	  var $published = null;
	   /**
	  * @var int
	  */
	  var $ordering = null;
	 /**
	  * @var int
	  */
	  var $hits = null;
	
	 /**
	  * Constructor
	  *
	  * @param object Database connector object
	  */
	  function __construct(& $db) {
	  parent :: __construct('#__arts_curriculum', 'id', $db);
	  }
	

	/**
     * Overloaded bind function
     *
     * @param array $array  Array or object of values to bind
     * @param mixed $ignore Array or space separated list of fields not to bind
     *
     * @return null|string Success returns null, failure returns an error
     * @access public
     * @see    JTable:bind
     */
	  
	  	function bind($array, $ignore = '')
	  	{
	
	  		if (key_exists('params', $array) && is_array($array['params'])) {
	  		$registry = new JRegistry();
	  		$registry->loadArray($array['params']);
	  		$array['params'] = $registry->toString();
	  		}
	 
	 		return parent :: bind($array, $ignore);
	 
	   		if (key_exists( 'subject', $array ) && is_array( $array['subject'] )) {
                $array['subject'] = implode( ',', $array['subject'] );
        		}
 
        	return parent::bind( $array, $ignore );
    		
    		if (key_exists( 'medium', $array ) && is_array( $array['medium'] )) {
                $array['medium'] = implode( ',', $array['medium'] );
        		}
 
        	return parent::bind( $array, $ignore );
	 	}
	 
	 
	 
/**
* Overloaded check method to ensure data integrity
*
* @access public
* @return boolean True on success
*/
	  	function check()
	  	{
	  
	  	/** check for valid name */
	 	if (trim($this->title) == '') {
	  	$this->_error = JText :: _('Please provide a valid title');
	  	return false;
	  	}
	 
	 
	 	/** check for existing name */
	  	$query = 'SELECT id FROM #__arts_curriculum WHERE title = ' . $this->_db->Quote($this->title) . ' AND catid = ' . (int)  	 $this->catid;
	  	$this->_db->setQuery($query);
	 	$xid = intval($this->_db->loadResult());
	 
	 	if ($xid && $xid != intval($this->id)) {
	  	$this->_error = JText :: sprintf('WARNNAMETRYAGAIN', JText :: _('Item'));
	  	return false;
	  	}
	  
	  	if(empty($this->alias)) {
	  	$this->alias = $this->title;
	  	}
	  
	  	$this->alias = JFilterOutput::stringURLSafe($this->alias);
	  
	  	if(trim(str_replace('-','',$this->alias)) == '') {
	  	$datenow =& JFactory::getDate();
	  	$this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
	 	 }
	 	
	 	jimport('joomla.filter.output');
	 	return true;
	  }
}
